package com.vpen.netty.demo.client;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.CharsetUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * 描述
 *
 * @author 韦鹏
 * @date 2022/11/11 21:24
 */
@Slf4j
public class HelloWorldClientHandler extends SimpleChannelInboundHandler<ByteBuf> {
    //    ByteBuf:字节序列，通过ByteBuf操作基础的字节数组和缓存区

    /**
     * 处理接受到的消息
     **/
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
        System.out.println("客户端收到的消息：" + msg.toString(CharsetUtil.UTF_8));
    }

    /**
     * 异常处理
     **/
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        System.out.println("出现异常了");
        super.exceptionCaught(ctx, cause);


    }
}
